package com.zhangyj.impl.actions;

import com.zhangyj.action.AbstractAction;
import com.zhangyj.action.RequestAction;
import com.zhangyj.action.RequestMethod;
import com.zhangyj.dao.DaoManager;
import com.zhangyj.dao.RoleDao;
import com.zhangyj.db.DBUtil;
import com.zhangyj.entitis.Role;
import com.zhangyj.util.Tools;
@RequestAction(name="role")
public class RoleAction extends AbstractAction {
	private static final long serialVersionUID = -3296297141184587402L;

	@RequestMethod(name = "save")
	public void save() throws Exception {
		String oper = this.getParameter("oper");
		String rolename = this.getParameter("rolename");
		String remark = this.getParameter("remark");
		int id = -1;
		if ("add".equals(oper)) {
			id = DBUtil.getIntId("roleinfo");
		} else {
			id = this.getIntParameter("roleid");
		}
		Role role = new Role();
		role.setRemark(remark);
		role.setRoleid(id);
		role.setRolename(rolename);
		RoleDao rd = DaoManager.getDao(RoleDao.class);
		if ("add".equals(oper)) {
			rd.addRole(role);
		} else if ("edit".equals(oper)) {
			rd.editRole(role);
		} else if ("del".equals(oper)) {
			rd.delRole(id);
		}
		response.setContentType("application/json;charset=UTF-8");
		Tools.formSuccess(response.getWriter(), "", role);
	}
}
